﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MLM.Data;
using MLM.Base;

namespace MLM.AdminCP.Pages
{
    public partial class MyHierarchy : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            long userId = Permission.GetCurrentUserId();
            MLMDataContext ct = new MLMDataContext();
            var user = ct.Users.FirstOrDefault(it => it.UserId == userId);

            Template = "[{v:'" + userId + "',f:'" + user.FirstName + " " + user.LastName + "<p>" + userId + "</p>'},'',''],";
            GetHierarchy(userId);
        }
        public static string Template = "";
        public static void GetHierarchy(long sponsorid)
        {
            MLMDataContext ct = new MLMDataContext();
            IQueryable<User> queryable = ct.Users.Where(it => it.SponsorID == sponsorid);
            foreach (var user in queryable)
            {
                Template += "[{v:'" + user.UserId + "',f:'" + user.FirstName + " " + user.LastName + "<p>" + user.UserId + "</p>'},'" + sponsorid + "',''],";
                GetHierarchy(user.UserId);
            }
        }
    }
}